<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
 <th:block th:include="include :: header('在线编辑')" />
    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/ajax/libs/wps/web-office-sdk-v1.1.8.umd.js}"></script>
    <script type="text/javascript">
        // 支持 HTTPS
        // 注意：如果通过postMessage来设置token，请在url参数加上_w_tokentype=1
        var wps;
        function showWPS() {

            console.log(window.location.host)
            $.get("/weboffice/url?_w_fileid=[[${wFileId}]]" , function(result) {
                console.log(result);

                wps = WebOfficeSDK.config({
                    mode: 'normal',
                    mount: document.querySelector('#viewIframe'),
                    url:result.wpsUrl,
                    headers: {
                        // downBtn: {
                        //     tooltip: '下载',
                        //     subscribe() {
                        //         // window.open("http:/"+window.location.host+"/weboffice/getFile?_w_fileid=[[${wFileId}]]")
                        //         window.open("http://"+window.location.host+"/weboffice/getFile?_w_fileid=[[${wFileId}]]");
                        //     }
                        // },
                        otherMenuBtn: {
                            tooltip: '下载',
                            items: [
                                {
                                    // 自定义, type 固定填 'custom'
                                    type: 'custom',
                                    // icon: 'https://img.qwps.cn/1158607268_c2afda9f620b3d6936cd8b8876e9629c?imageMogr2/thumbnail/180x180!',
                                    text: '下载word',
                                    async subscribe(wps) {
                                                window.open("http://"+window.location.host+"/weboffice/getFile?_w_fileid=[[${wFileId}]]");

                                    }
                                }
                            ]
                        }

                    }
                });

            })


            return wps
        }
        async function edit_status(){
            console.log(wps)
            await wps.ready()
             wps.WordApplication().ActiveDocument.TrackRevisions = true
            console.log("test")
        }
        window.onload = function() {
            var wps = showWPS()
            setTimeout(function () {
                edit_status()
            }, 1000); //1s

        }
    </script>
</head>

<body>
<div id="viewIframe" style="width: 100%;height: 100%"></div>
<!--<button onclick="edit_status()">修订</button>-->

</body>


<style>

    * {
        box-sizing: border-box;
    }

    html,
    body {
        display: flex;
        flex-direction: column;
        padding: 0;
        margin: 0;
        height: 100%;
        /* 防止双击缩放 */
        touch-action: manipulation;
    }

    iframe {
        flex: 1;
    }
    #viewIframe #wps-iframe{
        width:100%;
        height: 100%;
    }
  </style>
</html> 